from typing import Any
import pygame
from pygame.sprite import AbstractGroup, Sprite


class Target(Sprite):
    """
    目标
    """

    def __init__(self, car) -> None:
        super().__init__()
        self.car = car
        self.screen = car.screen
        self.world_x = float(200)
        self.world_y = float(200)
        self.width = 10
        self.height = 10
        pass

    def update(self) -> None:
        screen_rect = self.screen.get_rect()
        world_rect = pygame.Rect(self.world_x - self.width / 2, self.world_y + self.height / 2, self.width, self.height)
        win_rect = self.car.world_rect_to_win_rect(world_rect)

        if not screen_rect.colliderect(win_rect):
            return

        pygame.draw.rect(self.screen, (255, 0, 0), win_rect)
        pass

    def update_position(self, x, y):
        self.world_x = x
        self.world_y = y
